/*
 * @Description:
 * @Author: maxyang
 * @Date: 2022-06-28 08:15:12
 * @LastEditTime: 2022-06-28 21:56:01
 * @LastEditors: liutq
 * @Reference:
 */
package goods

import (
	"net/http"

	"github.com/gin-gonic/gin"
	"github.com/maxyang107/jinglan/common"
	"github.com/maxyang107/jinglan/service"
	"github.com/maxyang107/jinglan/utils"
)

/**
 * @description: 方法描述：申请回购
 * @Author: maxyang
 * @return {*}
 * @param {*gin.Context} c
 */
func AddRepoRecord(c *gin.Context) {
	var param common.Repo

	if err := c.ShouldBind(&param); err != nil {
		common.ResponseToJson(http.StatusOK, common.ParamError, err.Error(), c)
		return
	}

	userid, exists := c.Get("UserId")
	if !exists {
		common.ResponseToJson(http.StatusOK, common.NotAuth, "token解析失败", c)
		return
	}
	param.UId = utils.InterfaceToUser(userid)
	err := service.GoodsService.AddRepoRecord(param)
	if err != nil {
		common.ResponseToJson(http.StatusOK, common.Fail, err.Error(), c)
		return
	}

	common.ResponseToJson(http.StatusOK, common.Ok, "申请成功，预计7个工作日到账，请留意转账信息", c)
}
